<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>箭头函数-defineProperty</title>
    </head>
    <body>
        <h1>箭头函数-defineProperty</h1>
        <p>来源:<a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/Arrow_functions">https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/Arrow_functions</a></p>
        <h2>defineProperty</h2>
        <script>
            'use strict';
            var obj = {
              a: 10
            };

            Object.defineProperty(obj, "b", {
              get: () => {
                console.log(this.a, typeof this.a, this);// undefined "undefined" Window {}
                return this.a+10; // NaN
               // 代表全局对象 'Window', 因此 'this.a' 返回 'undefined'
              }
            });
        </script>
    </body>
</html>